# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_barscan_send_base_dt import jms_dwd__dwd_tab_barscan_send_base_dt
from jms.dwd.tab.dwd_tab_barscan_arrival_base_dt import jms_dwd__dwd_tab_barscan_arrival_base_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dim.dim_ep_flow_direction_base import jms_dim__dim_ep_flow_direction_base
from jms.dim.dim_ep_center_person_base import jms_dim__dim_ep_center_person_base
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.tms.dwd_tmsnew_shipment_union_base_dt import jms_dwd__dwd_tmsnew_shipment_union_base_dt
from jms.dwd.dwd_ep_create_institution_base import jms_dwd__dwd_ep_create_institution_base
from jms.time_sensor.time_after_05_45 import time_after_05_45

jms_dm__dm_tab_scan_piece_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_tab_scan_piece_detail_dt',
    task_concurrency=1,
    email=['jokic.wang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_scan_piece_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_tab_scan_piece_detail_dt/execute.hql',
    # sla=timedelta(hours=7),
    driver_memory='5G',
    driver_cores=1,
    executor_memory='8G',
    executor_cores=5,
    num_executors=44,
    pool_slots=2,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 48,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 600,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '4G',  # 堆外内存
          'spark.sql.shuffle.partitions': 720,
          'spark.yarn.maxAppAttempts': 1,
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=5'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 20,
              'hive.exec.max.dynamic.partitions': 20,
              },
    yarn_queue='pro',
    execution_timeout=timedelta(minutes=60),
)

jms_dm__dm_tab_scan_piece_detail_dt << [
    jms_dwd__dwd_tab_barscan_send_base_dt,
    jms_dwd__dwd_tab_barscan_arrival_base_dt,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_ep_flow_direction_base,
    jms_dim__dim_ep_center_person_base,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dwd__dwd_tmsnew_shipment_union_base_dt,
    jms_dwd__dwd_ep_create_institution_base,
    time_after_05_45
]
